// custom-tab-bar.js
const app = getApp()

Component({
  data: {
    selected: 0,
    color: "#bfbfbf",
    selectedColor: "#8abf00",
    backgroundColor: "#F7F8F8",
    list: [
      {
        pagePath: "/pages/index/index",
        iconPath: "/assets/icon/home.png",
        selectedIconPath: "/assets/icon/home-on.png",
        text: "首页",
      },
      {
        pagePath: "/pages/helper/helper",
        iconPath: "/assets/icon/helper.png",
        selectedIconPath: "/assets/icon/helper-on.png",
        text: "助手"
      },
      {
        pagePath: "/pages/common/common",
        bulge: true,
        iconPath: "/assets/icon/common.png",
        selectedIconPath: "/assets/icon/common-on.png",
        text: "常用"
      },
      {
        pagePath: "/pages/analyze/analyze",
        iconPath: "/assets/icon/analyze.png",
        selectedIconPath: "/assets/icon/analyze-on.png",
        text: "分析",
      },
      {
        pagePath: "/pages/my/my",
        iconPath: "/assets/icon/my.png",
        selectedIconPath: "/assets/icon/my-on.png",
        text: "我"
      }
    ]
  },
  attached() {
    this.setData({ selected: app.globalData.selected });
  },
  methods: {
    switchTab(e) {
      const idx = e.currentTarget.dataset.index
      const path = e.currentTarget.dataset.path

      wx.switchTab({ url: path });
      this.setData({ selected: idx });
      app.globalData.selected = idx;
    }
  }
})
